#ifndef __ATHOME_UTILITY_H_
#define __ATHOME_UTILITY_H_

#include <string>
#include <crow.h>

namespace utility {
  bool read_file(const std::string& file, std::string *content);
  bool write_file(const std::string& file, const char* data, size_t len);
  bool json_read_file(const std::string& file, crow::json::rvalue *json);
  bool json_write_file(const std::string& file, const crow::json::wvalue &json);
  
  enum class ResponseFileType {
    Null, Text, Json, Css, Image
  };
  crow::response response_file(const std::string& file, ResponseFileType type = ResponseFileType::Null);
  ResponseFileType guess_response_file_type_with_extension(const std::string& lower_extension);

  // len == 0 : use str len.
  bool str_start_with(const char *src, const char *str, size_t len = 0);
  bool str_end_with(const char *src, const char *str, size_t len = 0);

  // return lower
  std::string file_extension(const std::string &file);
  std::string file_path(const std::string &file);

  //
  std::string generate_random_hex(const unsigned int len);
  std::string base64_encode(const std::string &str);
  std::string base64_decode(const std::string &str);

  //
  enum class eHttpMethod {
    Null = 1,
    Get = 1,
    Post = 2,
    Delete = 4,
    Put = 8,
  };
  enum class eApiType {
    Simple,
    Number,
    Float,
    String,
    Path
  };
  eHttpMethod get_method_type(const std::string &str);
  eApiType get_api_type(const std::string &str);
}

#endif //__ATHOME_UTILITY_H_